<template>
	<view>
		<template v-if="list.length > 0">
			<block v-for="(item,index) in list" :key="index">
				<index-list :item="item" :index="index"></index-list>
			</block>
			<!-- 上拉加载 -->
			<load-more :loadtext="loadtext"></load-more>
		</template>
		<template v-if="isSearch && list.length === 0">
			<!-- 无内容默认 -->
			<no-thing></no-thing>
		</template>
	</view>
</template>

<script>
	import indexList from "../../components/index/index-list.vue"
	import loadMore from "../../components/common/load-more.vue"
	import noThing from "../../components/common/no-thing.vue"

	export default {
		data() {
			return {
				isSearch:false,
				loadtext: "上拉加载更多",
				list: [],
				searchText:""
			};
		},
		methods: {
			// 上拉加载
			loadmore() {
				if (this.loadtext !== "上拉加载更多") {
					return
				}
				// 修改状态
				this.loadtext = "拼命加载中. . ."
				setTimeout(() => {
					this.loadtext = "人家是有底线的 Ծ ‸ Ծ"
				}, 1000)
			},
			// 搜索事件
			getData(value) {
				uni.showLoading()
				// 请求事件
				setTimeout(() => {
					let arr = [{
							userpic: "../../static/image/userpic/12.jpg",
							username: "昵称",
							isfollow: false,
							title: "我是标题",
							type: "img", // img:图文 , video:视频
							titlepic: "../../static/image/datapic/11.jpg",
							infonum: {
								status: 0, // 0 没有操作,1 顶 ,2 踩
								dingnum: 11,
								cainum: 11
							},
							commentnum: 10,
							sharenum: 10
						},
						{
							userpic: "../../static/image/userpic/12.jpg",
							username: "昵称",
							isfollow: false,
							title: "我是标题",
							type: "video", // img:图文 , video:视频
							titlepic: "../../static/image/datapic/11.jpg",
							playnum: "20w",
							long: "2:47",
							infonum: {
								status: 0, // 0 没有操作,1 顶 ,2 踩
								dingnum: 11,
								cainum: 11
							},
							commentnum: 10,
							sharenum: 10
						}
					]
					this.list = arr
					uni.hideLoading()
					this.isSearch = true
				}, 1000)
			}
		},
		components: {
			indexList,
			loadMore,
			noThing
		},

		// 监听原生标题导航事件
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				// 点击了取消
				uni.navigateBack();
			}
		},
		// 监听搜索输入框事件
		onNavigationBarSearchInputChanged(e) {
			this.searchText = e.text
		},
		// 监听点击搜索按钮事件
		onNavigationBarSearchInputConfirmed(e) {
			if (e.text) {
				this.getData(e.text)
			}
		},
		// 监听页面触底事件
		onReachBottom() {
			this.loadmore()
		},
		// 监听下拉刷新
		onPullDownRefresh() {
			this.getData()
			uni.stopPullDownRefresh()
		},
		mounted() {
			let a = document.getElementsByClassName('uni-page-head-hd')[0]
			a.style.display = 'none'
			let b = document.querySelectorAll(".uni-btn-icon")[1]
			b.style.height = "20px"
		}
	}
</script>

<style lang="scss">

</style>
